from pymysql import connect

conc = connect(
    host="127.0.0.1",
    port=3306,
    user="root",
    password="123456",
    autocommit=True
)
cursor=conc.cursor()
conc.select_db("test")
# try:
#     cursor.execute("create table test_mysql("
#                    "id bigint primary key auto_increment,"
#                    "name varchar(16));")
# except Exception as e:
#     print(e)
#     conc.rollback()
# finally:
#     cursor.close()
#     conc.close()

# try:
#     cursor.execute("select * from test_mysql;")
#     result=cursor.fetchall()
#     for e in result:
#         print(e)
# except Exception as  e:
#     print(e)
#     conc.rollback()
# finally:
#     cursor.close()
#     conc.close()

try:
    cursor.execute("insert into test_mysql (name) values ('xiaoliang');")
    conc.commit()
except Exception as e:
    print(e)
    conc.rollback()
finally:
    cursor.close()
    conc.close()